data1<-read.csv("data.csv")

#descriptives#
#Table1#
#age#
summary(data1$B1PAGE_M2.x, na.rm=TRUE)
sd(data1$B1PAGE_M2.x, na.rm=TRUE)

#gender#
data1$gender<-NA
data[data1$B1PGENDER=="1" & !is.na(data1$B1PGENDER),]$gender=1
data[data1$B1PGENDER=="2" & !is.na(data1$B1PGENDER),]$gender=0

summary(data$gender, ns.rm=TRUE)

#income
data1$B1STINC1[data1$B1STINC1==9999998]<-NA
summary(data1$B1STINC1, na.rm=TRUE)
sd(data1$B1STINC1, na.rm=TRUE)


#fixing race variable

summary(data1$race, na.rm=TRUE)
sd(data1$race, na.rm=TRUE)


#marital status

summary(data1$marital)
sd(data1$marital, na.rm=TRUE)

#Average daily stressor total


summary(data1$B2DN_STR)
sd(data1$B2DN_STR, na.rm=TRUE)


#Avg Daily NA level
sd(data1$B2DNEGAV, na.rm=TRUE)
summary(data1$B2DNEGAV)

#Daily NA variability-Requires within-person data
summary(data1$sdNA)
sd(data1$sdNA)

#Past Life Satisfaction
data1$B1SQ2[data1$B1SQ2==98]<-NA
data1$B1SQ2[data1$B1SQ2==99]<-NA
mean(data1$B1SQ2, na.rm=TRUE)
sd(data1$B1SQ2, na.rm=TRUE)
#current life satisfaction
data1$B1SQ1[data1$B1SQ1==98]<-NA
data1$B1SQ1[data1$B1SQ1==99]<-NA
mean(data1$B1SQ1, na.rm=TRUE)
sd(data1$B1SQ1, na.rm=TRUE)
#future life satisfaction
data1$B1SQ3[data1$B1SQ3==98]<-NA
data1$B1SQ3[data1$B1SQ3==99]<-NA
mean(data1$B1SQ3, na.rm=TRUE)
sd(data1$B1SQ3, na.rm=TRUE)



library(pvclust)

temp<-na.exclude(data1)
fit<-kmeans(temp, 3)
aggregate(temp, by=list(fit$cluser), FUN=mean)
temp<-data.frame(temp, fit$cluster)
